﻿using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using WinSupperUpdateService.Store;

namespace WinSupperUpdateService.Model
{
	internal class PluginMeta
	{
		/// <summary>
		/// Meta文件版本
		/// </summary>
		public int MetaVersion { get; set; } = 1;

		/// <summary>
		/// 软件名
		/// </summary>
		public string SoftwareName { get; set; }

		/// <summary>
		/// 软件版本
		/// </summary>
		public string SoftwareVersion { get; set; }

		/// <summary>
		/// 软件版本号
		/// </summary>
		public int SoftwareVersionCode { get; set; }

		/// <summary>
		/// 软件更新内容通知
		/// </summary>
		public string SoftwareUpdateMsg { get; set; }

		/// <summary>
		/// 软件升级包路径
		/// </summary>
		public string SoftwareUpdatePackagePath { get; set; }

		/// <summary>
		/// 软件升级包Md5校验码
		/// </summary>
		public string SoftwareUpdatePackageMd5 { get; set; }

		/// <summary>
		/// 插件列表
		/// </summary>
		public List<PluginEntity> Plugins { get; set; } = new List<PluginEntity>();
	}

	internal static class PluginMetaTester
	{
		public static void GenerateMetaFile()
		{
			PluginMeta pluginMeta = new PluginMeta()
			{
				SoftwareName = "FxWinSupper",
				SoftwareVersionCode = 1,
				SoftwareVersion = "1.0.0",
				SoftwareUpdateMsg = "暂时没啥更新哦!",
				SoftwareUpdatePackagePath = @"software\FxWinSupperV1.0.2.zip",
				SoftwareUpdatePackageMd5 = "120E2C8A223238D02769C2E6AF0F4403"
			};
			pluginMeta.Plugins.Add(new PluginEntity()
			{
				Author = "风珝",
				PackagePath = @"plugins\Test\1\Test_new.zip",
				PackageMd5 = "120E2C8A223238D02769C2E6AF0F4403",
				PluginName = "Test",
				Statement = "测试插件",
				Version = "1.0",
				VersionCode = 1,
				DependencySoftwareVersionCode = 0
			});
			File.WriteAllText(FileSystemPluginStore.PluginMetaFile, JsonConvert.SerializeObject(pluginMeta, Formatting.Indented));
		}
	}
}
